<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <title>首页</title>
  <link rel="stylesheet" href="../../libs/element-ui@2.12.0.css" />
  <link rel="stylesheet" href="../../libs/common.css" />
  <link rel="stylesheet" href="../../libs/codemirror/codemirror@5.51.0.css" />
  <link rel="stylesheet" href="../../libs/codemirror/lint@5.51.0.css" />
  <link rel="stylesheet" href="./index.css" />
  <style>
    div[v-cloak] {
      display: none;
    }
  </style>
</head>
<body>
  <div id="root" v-cloak>
    <el-container>
      <el-header>
        <div class="logo"><img src="../../../logo.png" alt="" width="30" height="30" style="margin-top: 15px;"></div>
        <div class="project">{{projectName}}</div>
        <div class="section">
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              更多选项<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="createApi">新建接口</el-dropdown-item>
              <!-- <el-dropdown-item command="extendGlobleJs">拓展规则</el-dropdown-item> -->
              <el-dropdown-item command="switchProject">切换项目</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <div class="right"><el-button type="text" @click="startServer">启动服务</el-button></div>
      </el-header>
      <el-container>
        <el-aside>
          <el-menu
              @select="handleSelect"
              class="el-menu-vertical">
            <el-submenu index="api">
              <template slot="title">
                <i class="el-icon-coin"></i>
                <span>数据接口</span>
              </template>
              <el-menu-item-group>
                <el-menu-item v-for="(api, idx) in apis" :index="`${idx}`" :key="api.name">{{api.name}}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main style="display: flex;flex-flow: row nowrap;">
          <div class="main-left" v-show="showApiDetail">
            <div class="left"><textarea id="json_editor_input"></textarea></div>
            <div class="center" id="json_editor_btn">
              <div style="position:absolute;top:0;left:5px">
                <el-radio v-model="currentCodeMode" label="application/json">json</el-radio>
                <el-radio v-model="currentCodeMode" label="javascript">js</el-radio>
              </div>
              <el-row>
                <el-button v-show="currentCodeMode === 'application/json'" type="text" @click="test">运行</el-button>
              </el-row>
              <el-row>
                <el-button type="text" @click="save">保存</el-button>
              </el-row>
            </div>
            <div class="right" id="json_editor_result"></div>
          </div>
          <div class="main-right">
            <el-card class="box-card" style="margin-left: 10px;">
              <div slot="header" class="clearfix">
                <span>{{onlyProject.projectName}}</span>
                <el-button style="float: right; padding: 3px 0" type="text" @click="modifyProject">确定修改</el-button>
              </div>
              <el-form :model="onlyProject" :rules="rules" ref="onlyProject" label-position="top">
                <el-form-item label="项目名称" prop="projectName">
                  <el-input v-model="onlyProject.projectName" size="small"></el-input>
                </el-form-item>
                <el-form-item label="主机名" prop="host">
                  <el-input v-model="onlyProject.host" size="small"></el-input>
                </el-form-item>
                <el-form-item label="端口" prop="port">
                  <el-input v-model="onlyProject.port" size="small"></el-input>
                </el-form-item>
                <el-form-item label="请求前缀" prop="baseUrl">
                  <el-input v-model="onlyProject.baseUrl" size="small"></el-input>
                </el-form-item>
              </el-form>
            </el-card>
            <el-card class="box-card" v-show="showApiDetail" style="margin-top: 10px;margin-left: 10px;margin-bottom: 5px;">
              <div slot="header" class="clearfix">
                <span>{{onlyApi.name}}</span>
                <el-button style="float: right; padding: 3px 0; color: red;" type="text" @click="delApi">删除</el-button>
              </div>
              <el-form :model="onlyApi" disabled label-position="top">
                <el-form-item label="接口名" prop="name">
                  <el-input v-model="onlyApi.name" size="small"></el-input>
                </el-form-item>
                <el-form-item label="URL" prop="url">
                  <el-input v-model="onlyApi.url" size="small"></el-input>
                </el-form-item>
                <el-form-item label="请求地址" prop="url">
                  <el-input v-model="reqAddress" size="small"></el-input>
                </el-form-item>
                <el-form-item label="请求类型" prop="type">
                  <el-checkbox-group v-model="onlyApi.type">
                    <el-checkbox label="GET" name="type"></el-checkbox>
                    <el-checkbox label="POST" name="type"></el-checkbox>
                    <el-checkbox label="PUT" name="type"></el-checkbox>
                    <el-checkbox label="DELETE" name="type"></el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </el-form>
            </el-card>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>

  <script src="../../libs/vue@2.6.10.js"></script>
  <script src="../../libs/element-ui@2.12.0.js"></script>
  <script src="../../libs/mock-min@1.0.1-beta3.js"></script>
  <script src="../../libs/codemirror/codemirror@5.51.0.js"></script>
  <script src="../../libs/codemirror/codemirror-javascript@5.51.0.js"></script>
  <script src="../../libs/codemirror/jsonlint@1.6.3.min.js"></script>
  <script src="../../libs/codemirror/jshint@2.9.6.js"></script>
  <script src="../../libs/codemirror/lint@5.51.0.js"></script>
  <script src="../../libs/codemirror/json-lint@5.51.0.js"></script>
  <script src="../../libs/codemirror/javascript-lint@5.51.0.js"></script>
  <script src="./index.js"></script>
</body>
</html>
